<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>3_2_1-2-同步更新</title>
</head>

<body>


  <!--载入vue.js-->
  <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
  <h1>计算属性</h1>
  <div id="Application">
    <div id="Application">
      <div>{{ count }}</div>
      <div>{{ type }}</div>
      <button @click="add">Add</button>
    </div>
  </div>
  <script>
    //定义组件
    const App = {
      data() {
        return {
          count: 0,
        };
      },
      // computed选项定义计算属性
      computed: {
        type() {
          return this.count > 10 ? "大" : "小";
        },
      },
      methods: {
        add() {
          this.count++;
        },
      },
    };
    //创建组件并获取组件实例
    let instance = Vue.createApp(App).mount("#Application");

    //像访问普通属性一样访问计算属性
    console.log(instance.type);
  </script>
</body>

</html>